package com.dhp.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dhp.mapper.UserInterfaceInfoMapper;
import com.dhp.model.entity.UserInterfaceInfo;
import com.dhp.service.InnerUserInterfaceInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class innerUserInterfaceImpl implements InnerUserInterfaceInfoService {

    @Autowired
    private UserInterfaceInfoMapper userInterfaceInfoMapper;

    @Override
    public boolean doInvokeCount(Long userId, Long interfaceId) {
        LambdaQueryWrapper<UserInterfaceInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInterfaceInfo::getUserid , userId).eq(UserInterfaceInfo::getInterfaceinfoId , interfaceId);
        UserInterfaceInfo userInterfaceInfo = userInterfaceInfoMapper.selectOne(queryWrapper);
        userInterfaceInfo.setLeftNum(userInterfaceInfo.getLeftNum() - 1);
        userInterfaceInfo.setTotalNum(userInterfaceInfo.getTotalNum() + 1);
        int row = userInterfaceInfoMapper.updateById(userInterfaceInfo);
        return 1 == row;
    }
}
